{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "b27cd3ae-56eb-4ffe-a0d0-c841baa55f77",
   "metadata": {},
   "source": [
    "### 1.分词"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "dd76052e-c570-4a27-8260-a087ec0dc3dd",
   "metadata": {},
   "outputs": [],
   "source": [
    "import jieba"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "c255a316-4216-472a-8341-61a4c820caaf",
   "metadata": {},
   "outputs": [],
   "source": [
    "academy_titles = []\n",
    "job_titles = []"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "47578771-5830-409f-8d09-332b22b91df9",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Building prefix dict from the default dictionary ...\n",
      "Loading model from cache C:\\Users\\HP\\AppData\\Local\\Temp\\jieba.cache\n",
      "Loading model cost 0.343 seconds.\n",
      "Prefix dict has been built successfully.\n"
     ]
    }
   ],
   "source": [
    "#结巴分词的结果，采用list（）转为列表格式\n",
    "\n",
    "with open(\"academy_titles.txt\", encoding=\"utf-8\", mode=\"r\") as f:\n",
    "    for line in f:\n",
    "        academy_titles.append(list(jieba.cut(line.strip())))\n",
    "\n",
    "with open(\"job_titles.txt\", encoding=\"utf-8\", mode=\"r\") as f:\n",
    "    for line in f:\n",
    "        job_titles.append(list(jieba.cut(line.strip())))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "0093d619-7f9a-4385-b879-6c034f14e0b7",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[['北', '师', '教育学', '，', '你', '我', '一起', '努力', '，', '让', '胜利', '酣畅淋漓', '。'],\n",
       " ['考博', '英语词汇'],\n",
       " ['出售', '人大', '新闻', '学院', '2015', '年', '考研', '权威', '资料'],\n",
       " ['【', '脑科', '院', ' ', '郭桃梅', '课题组', '】', '科研', '助理', '招聘'],\n",
       " ['管理', '学院', '的', '同学', '帮帮忙', '呐', '～']]"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "academy_titles[:5]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1a00c91a-d73b-4fca-b1f1-88c4e433a2d4",
   "metadata": {},
   "source": [
    "### 2.统计词语数量"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "75b69c72-74f2-4879-b1ac-6ba6e503878b",
   "metadata": {},
   "outputs": [],
   "source": [
    "word_set = set()\n",
    "for line in academy_titles:\n",
    "    for word in line:\n",
    "        word_set.add(word)\n",
    "\n",
    "for line in job_titles:\n",
    "    for word in line:\n",
    "        word_set.add(word)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "cb8162dc-9272-4694-b323-cd87a0f6a68f",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "4085\n"
     ]
    }
   ],
   "source": [
    "print(len(word_set))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "5d88736b-fb77-4f1a-ae4b-b5a2970d188f",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  },
  "widgets": {
   "application/vnd.jupyter.widget-state+json": {
    "state": {},
    "version_major": 2,
    "version_minor": 0
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
